package com.ordertracker.entity;

import com.ordertracker.constant.GetByName;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Description of class.
 * Created 1/18/13 1:12 PM
 *
 * @author andrey.rodin@playtech.com
 */

@XmlRootElement
public class User extends VersionedEntity {

    private static final long serialVersionUID = 7536158330109712356L;
    private String name;
    private String login;
    private String password;
    private String description;
    private String email;
    private Role role;
    private Person person;
    private String locale;
    private String timezone;

    public User(Long id, Long version, String name, String login, String description, String email, Role role, Person person) {
        setId(id);
        setVersion(version);
        this.name = name;
        this.login = login;
        this.description = description;
        this.email = email;
        this.role = role;
        this.person = person;
    }

    public User() {
    }

    public enum Status implements GetByName<Status> {
        NEW("NEW"),
        ACTIVE("ACTIVE"),
        DEACTIVE("DEACTIVE"),
        BLOCKED("BLOCKED");

        private String name;

        Status(String name) {
            this.name = name;
        }

        public Status getByName(String name) {
            return null;
        }

        public String getName() {
            return name;
        }
    }

    @XmlElement(nillable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlElement(nillable = false)
    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }


    @XmlElement
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlElement(nillable = false)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @XmlElement(nillable = false)
    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @XmlElement
    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    @XmlElement(nillable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @XmlElement(nillable = false)
    public String getLocale() {
        return locale;
    }

    public void setLocale(String locale) {
        this.locale = locale;
    }

    @XmlElement(nillable = false)
    public String getTimezone() {
        return timezone;
    }

    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof User)) return false;
        if (!super.equals(o)) return false;

        User user = (User) o;

        if (description != null ? !description.equals(user.description) : user.description != null) return false;
        if (!email.equals(user.email)) return false;
        if (!login.equals(user.login)) return false;
        if (!name.equals(user.name)) return false;
        if (person != null ? !person.equals(user.person) : user.person != null) return false;
        if (!role.equals(user.role)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + login.hashCode();
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + email.hashCode();
        result = 31 * result + role.hashCode();
        result = 31 * result + (person != null ? person.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", login='" + login + '\'' +
                ", description='" + description + '\'' +
                ", email='" + email + '\'' +
                ", role=" + role +
                ", person=" + person +
                ", " + super.toString();
    }
}
